#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "basic_server_test.h"
#include "camera_features_server_test.h"
#include "IOT_errorCode.h"
#include "camera_param_init.h"
#include "device_param_init.h"
#include "IOT_errorCode.h"
#include "iot_comm_test.h"

void usage() {
    printf("this is a unit test function, select unit number to test functional \n");
    printf("usage: \n");
    printf("sdk_test_demo <unit num> \n");
    printf("1. iot_comm_test \n");
    printf("2. basic_server_test \n");
    printf("3. camera_features_server_test \n");
    printf("4. wait command \n");
}

int main(int argc, char **argv) {
    if (argc < 2) {
        usage();
        return -1;
    }

    if (iot_comm_init_test() == -1) {
        printf("iot_comm_init_test fail\n");
        return -1;
    }
    if (basic_server_init_test() == -1) {
        printf("basic_server_init_test fail\n");
        return -1;
    }
    if (camera_features_server_init_test() == -1) {
        printf("camera_features_server_init_test fail\n");
        return -1;
    }

    // 执行用户选项
    int keep_waiting = 0;
    int unit_num = atoi(argv[1]);
    switch (unit_num)
    {
    case 4:
        keep_waiting = 1;
        break;
    case 1:
        break;
    case 2:
        base_server_test();
        solarPowerServerInfo_test();
        longitudeAndLatitudeInfoUpload_test();
        commCardInfo_test();
        deviceFaultAlarmEventUpload_test();
        deviceTrafficInfoUpload_test();
        deviceSleepStatusUpload_test();
        break;
    case 3:
        camera_features_server_test();
        break;
    
    default:
        usage();
        break;
    }

    while (keep_waiting) {
        sleep(1);
    }

    iot_comm_init_test();
    phyModel_device_destroy();
    phyModel_camera_destroy();
    return 0;
}

